package com.masterclient.app.businessmodule.minemodule.redpack;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.eoner.baselib.widget.navgation.FCNavigationBar;
import com.eoner.middlelib.router.map.FCRouterPath;
import com.masterclient.app.R;
import com.masterclient.app.base.FCBusinessActivity;
import com.masterclient.app.businessmodule.minemodule.redpack.fragment.RedPackedFromFragment;
import com.masterclient.app.businessmodule.minemodule.redpack.fragment.RedPackedPayforFragment;
import com.masterclient.app.modules.bridge.BridgeActivity;
import com.masterclient.app.businessmodule.minemodule.redpack.adapter.RepackedPagerAdapter;
import com.eoner.baselibrary.utils.Utils;
import com.eoner.baselibrary.widget.EnhanceTabLayout;
import com.gyf.immersionbar.ImmersionBar;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 作者：sean
 * 创建时间：2017/8/5 09:38
 * 功能说明：
 */
@Route(path = FCRouterPath.MINE_GZB_PATH)
public class RedPackedActivity extends FCBusinessActivity {

    @BindView(R.id.rl_back)
    RelativeLayout rlBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rl_rule)
    LinearLayout rlRule;
    @BindView(R.id.ll_money)
    LinearLayout llMoney;
    @BindView(R.id.tabLayout)
    EnhanceTabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.tv_red_pack_num)
    TextView tvRedPackNum;
    @BindView(R.id.head_rl)
    RelativeLayout headRl;
    @BindView(R.id.status_bar)
    View statusBar;

    private List<Fragment> list;
    private RedPackedFromFragment redPackedFromFragment;
    private RedPackedPayforFragment redPackedPayforFragment;
    private RepackedPagerAdapter repackedPagerAdapter;
    String url;

    @Override
    protected int requireGetLayoutId() {
        return R.layout.activity_red_packed;
    }

    @Override
    protected void requireSetCustomNavigationBar(FCNavigationBar navigationBar) {
        navigationBar.setVisibility(View.GONE);
    }

    @Override
    protected void requireInitUIAndData(Bundle savedInstanceState) {
        ImmersionBar.with(this).statusBarDarkFont(true).statusBarView(statusBar).transparentStatusBar().init();

        Utils.setDin(tvRedPackNum,this);
        list = new ArrayList<>();
        redPackedFromFragment = new RedPackedFromFragment();
        redPackedPayforFragment = new RedPackedPayforFragment();
        list.add(redPackedFromFragment);
        list.add(redPackedPayforFragment);

        redPackedFromFragment.setOnDataListerner(new RedPackedFromFragment.OnDataListerner() {
            @Override
            public void getData(String bupiao,String url) {
                RedPackedActivity.this.url = url;
                DecimalFormat df=new DecimalFormat("#0.00");
                tvRedPackNum.setText(df.format(Float.valueOf(bupiao)));
            }
        });


        String [] sTitle = {"收入明细","支出明细"};
        repackedPagerAdapter = new RepackedPagerAdapter(getSupportFragmentManager(),list);
        for(int i=0;i<sTitle.length;i++){
            tabLayout.addTab(sTitle[i],i == 0);
        }
        viewPager.setAdapter(repackedPagerAdapter);

        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout.getTabLayout()));
        tabLayout.setupWithViewPager(viewPager);
    }

    @OnClick({R.id.rl_back,R.id.rl_rule}) void onClick(View view){
        switch (view.getId()){
            case R.id.rl_back:
                finish();
                break;
            case R.id.rl_rule:
                startActivitry(BridgeActivity.class,new String[][]{{"url",url},{"title","向日葵币说明"}});
                break;
        }
    }

}
